<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h3></h3>
    <script>

        var data = [{
            id: 1,
            name: '家电',
            goods: [{
                id: 11,
                gname: '冰箱',
                goods: [{
                    id: 111,
                    gname: '海尔'
                }, {
                    id: 112,
                    gname: '美的'
                },]
            }, {
                id: 12,
                gname: '洗衣机'
            }]
        }, {
            id: 2,
            name: '服饰'
        }];
        function Getid(join, id) {
            var o = null
            join.forEach(function (item) {
                if (item.id === id) {
                    // console.log(item);
                    o = item
                } else if (item.goods && item.goods.length > 0) {
                    o = Getid(item.goods, id)
                }
            })
            return o
        }
        // var h3 = document.querySelector('h3')
        var nas = Getid(data, 1)
        console.log(nas.id);
        console.log(nas.name);
        console.log(nas);
        // console.log(nams);
        // h3.innerHTML = nams
    </script>
</body>

</html>